﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Styx.WoWInternals.WoWObjects;
using Styx;
using Styx.Common;
using Styx.CommonBot;
using Styx.WoWInternals;
using System.Threading;
using System.Windows.Media;

namespace Milling
{
    public partial class Form2 : Form
    {
        private Styx.Helpers.Settings GuiSettingsBase;
        private string setting_path;

        public Form2(Styx.Helpers.Settings s, string path)
        {
            setting_path = path;
            GuiSettingsBase = s;
            InitializeComponent();
            propertyGrid1.SelectedObject = GuiSettingsBase;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            CRSettings.myPrefs.Save();
            if (CRSettings.myPrefs.AddersTongue) { MillHerbs(36903); }
            if (CRSettings.myPrefs.AncientLichen) { MillHerbs(22790); }
            if (CRSettings.myPrefs.ArthasTear) { MillHerbs(8836); }
            if (CRSettings.myPrefs.AzsharasVeil) { MillHerbs(52985); }
            if (CRSettings.myPrefs.Blindweed) { MillHerbs(8839); }
            if (CRSettings.myPrefs.Briarthorn) { MillHerbs(2450); }
            if (CRSettings.myPrefs.Bruiseweed) { MillHerbs(2453); }
            if (CRSettings.myPrefs.Cinderbloom) { MillHerbs(52983); }
            if (CRSettings.myPrefs.Deadnettle) { MillHerbs(37921); }
            if (CRSettings.myPrefs.Desecrated) { MillHerbs(89639); }
            if (CRSettings.myPrefs.Dragonsteeth) { MillHerbs(3819); }
            if (CRSettings.myPrefs.Dreamfoil) { MillHerbs(13463); }
            if (CRSettings.myPrefs.DreamingGlory) { MillHerbs(22786); }
            if (CRSettings.myPrefs.earthroot) { MillHerbs(2449); }
            if (CRSettings.myPrefs.Fadeleaf) { MillHerbs(3818); }
            if (CRSettings.myPrefs.Felweed) { MillHerbs(22785); }
            if (CRSettings.myPrefs.Firebloom) { MillHerbs(4625); }
            if (CRSettings.myPrefs.FireLeaf) { MillHerbs(39970); }
            if (CRSettings.myPrefs.FoolsCap) { MillHerbs(79011); }
            if (CRSettings.myPrefs.GhostMushroom) { MillHerbs(8845); }
            if (CRSettings.myPrefs.Goldclover) { MillHerbs(36901); }
            if (CRSettings.myPrefs.GoldenSansam) { MillHerbs(13464); }
            if (CRSettings.myPrefs.Goldthorn) { MillHerbs(3821); }
            if (CRSettings.myPrefs.GraveMoss) { MillHerbs(3369); }
            if (CRSettings.myPrefs.GreenTeaLeaf) { MillHerbs(72234); }
            if (CRSettings.myPrefs.Gromsblood) { MillHerbs(8846); }
            if (CRSettings.myPrefs.Heartblossom) { MillHerbs(52986); }
            if (CRSettings.myPrefs.Icecap) { MillHerbs(13467); }
            if (CRSettings.myPrefs.Icethorn) { MillHerbs(36906); }
            if (CRSettings.myPrefs.KhadgarsWhisker) { MillHerbs(3358); }
            if (CRSettings.myPrefs.Kingsblood) { MillHerbs(3356); }
            if (CRSettings.myPrefs.Lichbloom) { MillHerbs(36905); }
            if (CRSettings.myPrefs.Liferoot) { MillHerbs(3357); }
            if (CRSettings.myPrefs.MageRoyal) { MillHerbs(785); }
            if (CRSettings.myPrefs.ManaThistle) { MillHerbs(22793); }
            if (CRSettings.myPrefs.MountainSilversage) { MillHerbs(13465); }
            if (CRSettings.myPrefs.Netherbloom) { MillHerbs(22791); }
            if (CRSettings.myPrefs.Nightmarevine) { MillHerbs(22792); }
            if (CRSettings.myPrefs.peacebloom) { MillHerbs(2447); }
            if (CRSettings.myPrefs.PurpleLotus) { MillHerbs(8831); }
            if (CRSettings.myPrefs.Rageveil) { MillHerbs(22787); }
            if (CRSettings.myPrefs.RainPoppy) { MillHerbs(72237); }
            if (CRSettings.myPrefs.Silkweed) { MillHerbs(72235); }
            if (CRSettings.myPrefs.silverleaf) { MillHerbs(765); }
            if (CRSettings.myPrefs.SnowLily) { MillHerbs(79010); }
            if (CRSettings.myPrefs.Sorrowmoss) { MillHerbs(13466); }
            if (CRSettings.myPrefs.Stormvine) { MillHerbs(52984); }
            if (CRSettings.myPrefs.Stranglekelp) { MillHerbs(3820); }
            if (CRSettings.myPrefs.Sungrass) { MillHerbs(8838); }
            if (CRSettings.myPrefs.Swiftthistle) { MillHerbs(2452); }
            if (CRSettings.myPrefs.TalandrasRose) { MillHerbs(36907); }
            if (CRSettings.myPrefs.Terocone) { MillHerbs(22789); }
            if (CRSettings.myPrefs.TigerLily) { MillHerbs(36904); }
            if (CRSettings.myPrefs.TwilightJasmine) { MillHerbs(52987); }
            if (CRSettings.myPrefs.Whiptail) { MillHerbs(52988); }
            if (CRSettings.myPrefs.WildSteelbloom) { MillHerbs(3355); }

            Close();
        }
        public void MillHerbs(uint herb)
        {
            foreach (WoWItem item in StyxWoW.Me.BagItems)
            {
                if (item.Entry == herb && item.StackCount >= 5 && item.BagSlot != -1)
                {
                    while (item.StackCount >= 5 && item.BagSlot != -1)
                    {
                        Logging.Write(Colors.RoyalBlue, "[Milling]:Milling {0} ", item.Name);
                        SpellManager.Cast(51005);
                        Lua.DoString(string.Format("UseContainerItem({0}, {1})", item.BagIndex + 1, item.BagSlot + 1));
                        Thread.Sleep(2500);
                    }
                    if (StyxWoW.Me.FreeNormalBagSlots <= 2)
                    {
                        Logging.Write(Colors.Red, "Stopping Because Free Bagspace");
                        break;
                    }
                }
            }
        }
    }
}
